package fidl;

import java.io.File;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;

public class Utils {
	public static File createFile(String filename) {
		File file = new File(filename).getAbsoluteFile();
		File parent = file.getParentFile();
		if (parent != null && (parent.mkdirs() || parent.isDirectory())) {
			return file;
		}
		return null;
	}

	public static String fetchFileName(Resource resource) {
		URI uri = resource.getURI();
		if (uri.segmentCount() == 0) return "";
		String result = uri.segment(uri.segmentCount() - 1);
		return result.substring(0, result.lastIndexOf('.'));
	}
}
